#include "CommonDef.hlsli"

cbuffer cbView: register(b0)
{
    matrix g_ViewProjMatrix;
    float3 g_EyePos;
};

static const float2 g_QuadTexCoords[4] = {
    float2(-1.0f, -1.0f),
    float2(-1.0f, 1.0f),
    float2(1.0f, 1.0f),
    float2(1.0f, -1.0f)
};

[maxvertexcount(4)]
void main(
    point VertexOut vsOutputs[1],
    //Triangle Strips
    inout TriangleStream<GeoOut> outputGeos
)
{
    VertexOut input = vsOutputs[0];
    //对着人眼
    float3 center = input.finalPos.xyz;
    float3 lookTo = normalize(center - g_EyePos);
    float3 right = cross(lookTo, float3(0.0f, 1.0f, 0.0f));
    right = normalize(right);
    float3 up = normalize(cross(lookTo, right));
    float halfWidth = input.size.x / 2.0f;
    float halfHeight = input.size.y / 2.0f;
    float3 rightDelta = right * halfWidth;
    float3 upDelta = up * halfHeight;
    float3 positions[] = {
        center - rightDelta - upDelta,
        center - rightDelta + upDelta,
        center + rightDelta - upDelta,
        center + rightDelta + upDelta,
    };
   
    for (int i = 0; i < 4; ++i)
    {
        GeoOut output;
        output.position = mul(g_ViewProjMatrix, float4(positions[i], 1.0f));
        output.texCoord = g_QuadTexCoords[i];
        output.color = input.color;
        outputGeos.Append(output);
    }
}